package com.itheima.app.controller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    SettingManager settingManager;

    @GetMapping("/users/settings")
    public ResponseEntity findSetting(){
        return settingManager.findSetting();
    }

    @PostMapping("/users/questions")
    public void setQuestion(@RequestBody Map<String,String> map){
        //获取问题
        String content = map.get("content");
        settingManager.setQuestion(content);
    }

    @PostMapping("/users/notifications/setting")
    public void setNotification(@RequestBody Notification notification){
        settingManager.setNotification(notification);
    }

    //黑名单列表
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlackListByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize){
        return settingManager.findBlackListByPage(pageNum,pageSize);
    }

    //移除黑名单
    @DeleteMapping("/users/blacklist/{blackId}")
    public void deleteBlackList(@PathVariable Long blackId){
        settingManager.deleteBlackList(blackId);
    }

    //修改用户手机号码--发送验证码
    @PostMapping("/users/phone/sendVerificationCode")
     public void sendVerificationCode(){
        //调用manager完成发送验证码操作
        settingManager.sendCode();
     }

    //修改用户手机号码--校验验证码
    @PostMapping("/users/phone/checkVerificationCode")
    public Map checkVerificationCode(@RequestBody Map<String,String> map){
            return settingManager.checkVerificationCode(map);
    }

    //修改用户手机号--保存新手机号码
    @PostMapping("/users/phone")
    public ResponseEntity changePhone(@RequestBody Map<String,String> map){
        return settingManager.changePhone(map);
    }
}